/**
 * Class: Instrument
 *
 * Purpose: 
 *
 * Created: Jan 28, 2010 @ 4:38:00 PM
 * @author Ken Scott
 */
package org.openfantasia.musica.instruments;

import org.openfantasia.musica.Musica;
import org.openfantasia.musica.events.Event;
import org.openfantasia.musica.events.Note;
import net.beadsproject.beads.core.UGen;

public abstract class Instrument {

	protected String name = Event.DEFAULT_NAME;

	protected Musica musica;


	public Instrument(Musica musica) {
		this.musica = musica;
		this.name = getClass().getSimpleName();
	}


	public Musica getMusica() {
		return musica;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public void play(Note note) {
		UGen result = getEnvelope(note.getVolume(), musica.getNoteDuration(note.getDuration()));
		result.addInput(getSound(note.getFrequency()));
		musica.getOut().addInput(result);
		musica.start();
	}


	public abstract UGen getSound(double frequency);


	public abstract UGen getEnvelope(double volume, double durationNanos);
}